import { HTTP } from '../utils/httpProm.js'

class KeywordModel extends HTTP {
  key = 'qHistory'
  maxLength = 10
  setHistory (keyword) {
    let wordArr = this.getHistory()
    if (!wordArr.includes(keyword)) {
      if (wordArr.length >= this.maxLength) {
        wordArr.pop()
      }
      wordArr.unshift(keyword)
      wx.setStorageSync(this.key, wordArr)
    }
  }
  
  getHistory () {
    return wx.getStorageSync(this.key) || []
  }

  getHot () {
    return this.request({
      url: '/book/hot_keyword'
    })
  }
}

export { KeywordModel }